package cn.com.thinker.core.module.service.impl;

import cn.com.thinker.core.module.dao.jpa.DicRepository;
import cn.com.thinker.core.module.dao.mapper.UserMapper;
import cn.com.thinker.core.module.entity.Dic;
import cn.com.thinker.core.module.entity.User;
import cn.com.thinker.core.module.service.IDicService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;


/**
 * Created by crazyHC on 2017/6/9.
 */
@Slf4j
@Service("dicService")
public class DicServiceImpl implements IDicService{


    @Autowired
    private DicRepository dicRepository;
    @Autowired
    private UserMapper userMapper;

    @Override
    @Transactional
    public Dic saveDicWithRollBack(Dic dic,User user) {
        userMapper.insert(user);
        User userResult = userMapper.selectOne(user);
        dic.setUserId(userResult.getId());
        dic.setCreateTime(new Date());
        Dic dicResult = dicRepository.save(dic);
        throw new RuntimeException("异常回滚，用户crazyHC为null");
    }
}
